#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
int n;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    ll a[10005];
    ll b[10005];
    ll sum = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i < n; i++)
    {
        b[i] = a[i + 1] - a[i];
    }
    for (int i = 1; i < n; i++)
    {
        sum += (ll)(i * (n - i) * b[i]);
    }
    cout << sum * 2 << endl;
    return 0;
}
